#ifndef GLWIDGET_H
#define GLWIDGET_H

#include <QImage>
#include <QPainter>
#include <QOpenGLWidget>
#include <QOpenGLFunctions>

class GLWidget : public QOpenGLWidget, protected QOpenGLFunctions
{
    Q_OBJECT
public:
    GLWidget(QWidget *parent) : QOpenGLWidget(parent){
        bIsImage  = false;
    }
    void setImage(const QImage &img){
        bIsImage  = true;
        m_img = img;
        this->update();
    }
    void setImage2(const QPixmap &img){
        bIsImage  = false;
        m_img2 = img;
        this->update();
    }
private:
    QImage m_img;
    QPixmap m_img2;
    bool bIsImage;
protected:
    void paintEvent(QPaintEvent *) {
        QPainter p(this);
        p.setRenderHint(QPainter::SmoothPixmapTransform, 1);
        if(bIsImage) {
            p.drawImage(this->rect(), m_img);
        } else {
            p.drawImage(this->rect(), m_img2.toImage());
        }
    }
};

#endif // GLWIDGET_H
